package com.binance.notification.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import com.binance.master.models.APIRequest;
import com.binance.master.models.APIResponse;
import com.binance.notification.api.IAbnormalThresholdConfigApi;
import com.binance.notification.api.request.AddAbnormalConfigRequest;
import com.binance.notification.api.request.DeleteAbnormalConfigRequest;
import com.binance.notification.api.request.GetAbnormalConfigRequest;
import com.binance.notification.api.request.UpdateAbnormalConfigRequest;
import com.binance.notification.api.response.GetAbnormalConfigResponse;
import com.binance.notification.api.vo.PagingResult;
import com.binance.notification.web.service.IAbnormalThresholdConfigService;

@RestController
public class AbnormalThresholdConfigController implements IAbnormalThresholdConfigApi {

    @Autowired
    private IAbnormalThresholdConfigService abnormalThresholdConfigService;

    @Override
    public APIResponse<PagingResult<GetAbnormalConfigResponse>> getAbnormalConfigList(
            @RequestBody @Validated APIRequest<GetAbnormalConfigRequest> request) throws Exception {
        return APIResponse
                .getOKJsonResult(this.abnormalThresholdConfigService.getAbnormalConfigList(request.getBody()));
    }

    @Override
    public APIResponse<Void> addAbnormalConfig(@RequestBody @Validated APIRequest<AddAbnormalConfigRequest> request)
            throws Exception {
        this.abnormalThresholdConfigService.addAbnormalConfig(request.getBody());
        return APIResponse.getOKJsonResult();
    }

    @Override
    public APIResponse<Void> updateAbnormalConfig(
            @RequestBody @Validated APIRequest<UpdateAbnormalConfigRequest> request) throws Exception {
        this.abnormalThresholdConfigService.updateAbnormalConfig(request.getBody());
        return APIResponse.getOKJsonResult();
    }

    @Override
    public APIResponse<Void> deleteAbnormalConfig(
            @RequestBody @Validated APIRequest<DeleteAbnormalConfigRequest> request) throws Exception {
        this.abnormalThresholdConfigService.deleteAbnormalConfig(request.getBody().getIds());
        return APIResponse.getOKJsonResult();
    }

    @Override
    public APIResponse<GetAbnormalConfigResponse> findById(APIRequest<Long> request) throws Exception {
        return APIResponse.getOKJsonResult(this.abnormalThresholdConfigService.findById(request.getBody()));
    }

}
